{% extends "base.html" %}

{% block title %}帖子审核{% endblock %}

{% block content %}
<div class="container mt-4">
    <h2>帖子审核</h2>
    
    <div class="mb-4">
        <h4>设置审核员</h4>
        <form method="POST" action="{{ url_for('set_auditor') }}">
            <div class="input-group mb-3">
                <input type="text" class="form-control" name="auditor" placeholder="输入审核员用户名" required>
                <button class="btn btn-primary" type="submit">设为审核员</button>
            </div>
        </form>
    </div>

    <div class="table-responsive">
        <table class="table table-striped">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>标题</th>
                    <th>作者</th>
                    <th>发布时间</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                {% for post in posts %}
                <tr>
                    <td>{{ post.id }}</td>
                    <td>{{ post.title }}</td>
                    <td>{{ post.author.username }}</td>
                    <td>{{ post.created_at.strftime('%Y-%m-%d %H:%M') }}</td>
                    <td>
                        <a href="{{ url_for('approve_post', post_id=post.id) }}" class="btn btn-sm btn-success">通过</a>
                        <button class="btn btn-sm btn-danger" data-bs-toggle="modal" data-bs-target="#rejectModal{{ post.id }}">拒绝</button>
                        
                        <!-- 拒绝原因模态框 -->
                        <div class="modal fade" id="rejectModal{{ post.id }}" tabindex="-1" aria-labelledby="rejectModalLabel" aria-hidden="true">
                            <div class="modal-dialog">
                                <div class="modal-content">
                                    <div class="modal-header">
                                        <h5 class="modal-title" id="rejectModalLabel">拒绝帖子</h5>
                                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                                    </div>
                                    <form method="POST" action="{{ url_for('reject_post', post_id=post.id) }}">
                                        <div class="modal-body">
                                            <div class="alert alert-info mb-3">
                                                请注意：您填写的拒绝原因将对发帖人可见，请提供明确具体的修改建议。
                                            </div>
                                            <div class="mb-3">
                                                <label for="rejectionReason{{ post.id }}" class="form-label">拒绝原因</label>
                                                <textarea class="form-control" id="rejectionReason{{ post.id }}" name="rejection_reason" rows="3" required></textarea>
                                                <small class="form-text text-muted">请详细说明拒绝理由，帮助发帖人改进</small>
                                            </div>
                                        </div>
                                        <div class="modal-footer">
                                            <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
                                            <button type="submit" class="btn btn-danger">确认拒绝</button>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>
</div>
{% endblock %}
